package com.imooc.news_manager_project.controller;

import com.imooc.news_manager_project.common.Result;
import com.imooc.news_manager_project.common.validator.SaveValidator;
import com.imooc.news_manager_project.dto.CommentsDTO;
import com.imooc.news_manager_project.service.ICommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "评论数据管理接口")
@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private ICommentService commentService;


    @ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token值", required = true)
    @ApiOperation(value = "新增评论数据")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Validated(SaveValidator.class) CommentsDTO commentsDTO) {
        return commentService.save(request, commentsDTO);
    }

    @ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token值", required = true)
    @ApiOperation(value = "获取指定新闻的一级评论数据")
    @GetMapping("/getAllComments/{id}")
    public Result getAllNewsComments(@PathVariable("id") String id) {
        return commentService.getAllNewsComments(id);
    }


    @ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token值", required = true)
    @ApiOperation(value = "获取评论数据的所有回复数据内容")
    @GetMapping("/getReplyComments/{id}")
    public Result getReplyComments(@PathVariable("id") String id) {
        return commentService.getReplyComments(id);
    }




    @ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token值", required = true)
    @ApiOperation(value = "删除某个评论以及所有回复评论")
    @DeleteMapping("/removeComments/{id}")
    public Result removeComments(@PathVariable("id") String id) {
        return commentService.removeComments(id);
    }

    @ApiImplicitParam(paramType = "header", name = "token", value = "登录获取的token", required = true)
    @ApiOperation(value = "评论数据点赞操作")
    @GetMapping("/likes/{id}")
    public Result likesById(HttpServletRequest request,@PathVariable("id") String id) {
        return commentService.likesById(request, id);
    }
}
